package ar.com.ford.it.fullEconomics.persistence.dao;

import java.util.Collection;
import ar.com.ford.it.fullEconomics.persistence.dto.Teesp04Supply;
import ar.com.ford.it.fullEconomics.persistence.dto.Teesp05Pricing;
import ar.com.ford.it.webengine.persistence.PersistenceUtil;
import com.ford.it.logging.ILogger;
import com.ford.it.logging.LogFactory;
import com.ford.it.persistence.PersistenceException;
import com.ford.it.persistence.PersistenceManager;
import com.ford.it.persistence.Query;
import com.ford.it.persistence.Transaction;

public class SupplyDao extends Dao {
    private static final String CLASS_NAME = SupplyDao.class.getName();
    private static final ILogger log = LogFactory.getInstance().getLogger(
            CLASS_NAME);

    /**
     * Busca Parts segun code
     * 
     * @param code
     * @return
     * @throws PersistenceException
     */
    @SuppressWarnings("unchecked")
    public Collection<Teesp04Supply> findSupply(Teesp04Supply supply)
            throws PersistenceException {

        String METHOD_NAME = "findSupply";
        log.entering(CLASS_NAME, METHOD_NAME);

        Collection<Teesp04Supply> supplyCol = null;
        PersistenceManager pm = null;

        pm = PersistenceUtil.getPersistenceManager();
        Query query = pm.newQuery("findPartsBySupplier", Teesp04Supply.class);
        query.setParameters(supply);

        supplyCol = (Collection) pm.executeQuery(query);
        log.exiting(CLASS_NAME, METHOD_NAME);
        return supplyCol;
    }
    
    public Teesp05Pricing findPricing(Teesp05Pricing pricin)
    throws PersistenceException {

    String METHOD_NAME = "findPricing";
    log.entering(CLASS_NAME, METHOD_NAME);
    
    Teesp05Pricing pricing = new Teesp05Pricing();
    PersistenceManager pm = null;
    
    pm = PersistenceUtil.getPersistenceManager();
    Query query = pm.newQuery("findPricingBySupply", Teesp05Pricing.class);
    query.setParameters(pricin);
    
    pricing = (Teesp05Pricing) pm.executeQuery(query);
    
    
    
    log.exiting(CLASS_NAME, METHOD_NAME);
    
    return pricing;
    }

    public SupplyDao() {
        super();
    }

    /**
     * Create Supply
     * 
     * @param newSupply
     * @throws PersistenceException
     */
    public void createSupply(Teesp04Supply newSupply)
            throws PersistenceException {
        String METHOD_NAME = "createSupply";
        log.entering(CLASS_NAME, METHOD_NAME);
        Transaction tx = null;
        tx = PersistenceUtil.getTransaction();
        tx.registerInsert(newSupply);
        log.exiting(CLASS_NAME, METHOD_NAME);
    }

    /**
     * Elimina de forma definitiva de la base de datos el Supply pasado por
     * parametro
     * 
     * @param Supply
     * Debe haber sido obtenido de la base de datos
     * @throws PersistenceException
     * @throws PersistenceException
     */
    public void deleteSupply(Teesp04Supply supply) throws PersistenceException {
        String METHOD_NAME = "deleteSupply";
        log.entering(CLASS_NAME, METHOD_NAME);

        Transaction tx = PersistenceUtil.getTransaction();
        tx.registerDelete(supply);

        log.exiting(CLASS_NAME, METHOD_NAME);
    }
    
    /**
     * Retorna objeto para actualizacion
     * @param supply
     * @return
     * @throws PersistenceException
     */
     public Teesp04Supply getUpdateSupply(Teesp04Supply supply) throws PersistenceException {

            String METHOD_NAME = "getUpdateSupply";
            log.entering(CLASS_NAME, METHOD_NAME);

            Teesp04Supply result = null;
            result = (Teesp04Supply) super.getObjForUpdate(supply);

            log.exiting(CLASS_NAME, METHOD_NAME);
            return result;
      }
     
     /**
      * Retorna objeto segun el pk 
      * @param supply
      * @return
      * @throws PersistenceException
      */
      public Teesp04Supply getSupplyByPk(Teesp04Supply supply) throws PersistenceException {

             String METHOD_NAME = "getSupplyByPk";
             log.entering(CLASS_NAME, METHOD_NAME);

             Teesp04Supply result = null;
             result = (Teesp04Supply) super.getObjById(supply);

             log.exiting(CLASS_NAME, METHOD_NAME);
             return result;
       }     
}
